package anji.plus.system.mark.controller;


import anji.plus.system.mark.base.BaseController;
import anji.plus.system.mark.base.Header;
import anji.plus.system.mark.base.IBaseService;
import anji.plus.system.mark.domain.SysUser;
import anji.plus.system.mark.response.ResponseCode;
import anji.plus.system.mark.response.ResponseResult;
import anji.plus.system.mark.service.IPrizeRecordService;
import anji.plus.system.mark.service.ISysUserService;
import anji.plus.system.mark.service.ITaskListService;
import anji.plus.system.mark.utils.LoginUtils;
import anji.plus.system.mark.utils.PassportUtil;
import anji.plus.system.mark.utils.RedisUtil;
import com.sun.org.apache.xpath.internal.objects.XObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统用户表 前端控制器
 * </p>
 *
 * @author luwei
 * @since 2023-11-08
 */
@RestController
@RequestMapping("sys/prize")
public class PrizeRecordController extends BaseController {

    @Resource
    private IPrizeRecordService prizeRecordService;

    @Override
    public IBaseService getService() {
        return null;
    }


    /**
     * 抽奖
     *
     * @author zhouchong
     * @date 2023/12/13 11:47
     */
    @GetMapping({"prizeList"})
    public ResponseResult prizeList(String prizeLevel) {

            return ResponseResult.success(prizeRecordService.prizeList(prizeLevel));

    }

    @GetMapping({"raffle"})
    public ResponseResult raffle(String name, String prizeLevel, String prizeType) {
        //获取可用次数 availTimes
        String availTimes = prizeRecordService.queryUserTimes(name);
        Map<String, String> myMap1 = new HashMap<>();

        if ((name == "") && (name == null)) {
            // 判断账号
            return ResponseResult.failure(ResponseCode.PARAM_IS_BLANK);
        } else if (availTimes.equals("0")) {
            // 判断账号为空
            return ResponseResult.failure("抽奖次数不足");
        } else {
            String prizeCode = prizeRecordService.raffle(name, prizeLevel, prizeType);
            myMap1.put("prizeCode", prizeCode);
//            return ResponseResult.success((Object)prizeCode);
            return ResponseResult.success(myMap1);
        }
    }

    @GetMapping({"userRaffleInfo"})
    public ResponseResult userRaffleInfo(String name) {

        Map<String, String> myMap = new HashMap<>();
        Integer prizeLevel = prizeRecordService.queryUserInfo(name).getPrizeLevel();
        Integer availTimes = prizeRecordService.queryUserInfo(name).getAvailTimes();
        myMap.put("name", name);
        myMap.put("prizeLevel", String.valueOf(prizeLevel));
        myMap.put("availTimes", String.valueOf(availTimes));
        return ResponseResult.success(myMap);

    }

    @GetMapping({"prizeInfo"})
    public ResponseResult prizeInfo() {

        return ResponseResult.success(prizeRecordService.prizeInfo());

    }
}
